"""
监理日记
"""
import logging

import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool

# 测试用例数据
case_data = {'module':'施工管理','caseid':'CB01','lot':'大庄水厂、智慧谷工业园、龙港新区 应急供水工程（智慧谷工业园标段）','formsname':'测量方案报审','account1':'shigong1','username1':'陈凯','account2':'jianli1','username2':'张三'}

@pytest.mark.业务系统
@pytest.mark.监理管理
@allure.step(case_data['caseid'])
#@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    # 测试结果标题
    allure.dynamic.feature(case_data['module'])
    allure.dynamic.title(case_data['caseid'])
    allure.dynamic.suite(case_data['caseid'])

    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    allure.step("登录")
    page.goto(url+url_login)
    page.get_by_placeholder("请输入用户名").fill(case_data['account1'])
    page.get_by_placeholder("请输入密码").fill(password_admin)
    page.get_by_role("button", name="登 录").click()
    
    allure.step("跳转监理日记")
    page.goto(url+url_jianliriji)
    page.get_by_role("button", name=" 新建").click()
    #page.get_by_label("请选择标段").get_by_text(bd_zhihuigu).click()
    #page.get_by_role("button", name="确 定").click()
    page.get_by_placeholder("请输入天气").click()
    page.get_by_placeholder("请输入天气").fill("1")
    page.get_by_placeholder("请输入气温").click()
    page.get_by_placeholder("请输入气温").fill("1")
    page.get_by_placeholder("请输入风力").click()
    page.get_by_placeholder("请输入风力").fill("1")
    page.get_by_placeholder("请输入风向").click()
    page.get_by_placeholder("请输入风向").fill("1")
    page.get_by_role("button", name="发起流程").click()
    expect(page.get_by_role("alert")).to_contain_text("请求成功")


    allure.step("监理人员签字")
    page.locator("#tags-view-container").get_by_text("项目首页").click()
    page.get_by_role("row", name="1 【监理日记】").locator("span").nth(1).click()
    page.get_by_placeholder("请输入签署密码").fill(password_flow)
    page.get_by_placeholder("请选择签章").click()
    page.get_by_text("施工单位项目1部-企业公章").click()
    page.get_by_role("button", name="通 过").click()
    expect(page.locator("body")).to_contain_text("请求成功")
    # 断言
    #expect(page.get_by_text('新建成功！')).to_be_visible()

    page.goto(url + url_jianliriji)
    with page.expect_popup() as page1_info:
        page.get_by_role("button", name="报表预览").first.click()
    page1 = page1_info.value
    # 测试结果截图
    page.wait_for_timeout(1000)
    filename = os.path.join(test_screenshot_dir, f"{'监理日记'}.png")
    page1.screenshot(path=filename)
    allure.attach.file(source=filename, name='监理日记',
                       attachment_type=allure.attachment_type.PNG)


    context.close()
    SetupTeardown.close()


